package org.glut.friendsService.controller;

import org.glut.friendsService.entity.Messages;
import org.glut.friendsService.service.IMessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  前端控制器
 *
 * @author qjc
 * @since 2024-08-16 12:32
 */
@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private IMessagesService messageService;

    // 发送消息
    @PostMapping("/send")
    public String sendMessage(@RequestParam("senderId") Integer senderId,
                              @RequestParam("receiverId") Integer receiverId,
                              @RequestParam("content") String content) {
        boolean success = messageService.sendMessage(senderId, receiverId, content);
        return success ? "消息发送成功" : "消息发送失败";
    }

    // 获取聊天记录
    @GetMapping("/list")
    public List<Messages> getMessages(@RequestParam("senderId") Integer senderId,
                                      @RequestParam("receiverId") Integer receiverId) {
        return messageService.getMessages(senderId, receiverId);
    }
}
